package edu.hawaii.ics.pjdb.util;

import java.util.ArrayList;
import java.util.List;

import edu.hawaii.ics.pjdb.types.Tuple;

/**
 * Provides methods that might be useful in debugging functions in the PJDB
 * system.
 * 
 * @author Christopher Foo
 * 
 */
public class TestingHelpers {
    /**
     * Returns a String representation of the partitions. For debugging
     * purposes.
     * 
     * @param partitions
     *            The partitions to be converted to a String.
     * @return The String representation of the partitions.
     */
    public static void printPartition(
            ArrayList<ArrayList<Tuple>> partitions) {
        String printString = "";
        ArrayList<Tuple> partition;
        List<String> entries;
        int partitionSize, entriesSize;
        int numPartitions = partitions.size();
        for (int i = 0; i < numPartitions; i++) {
            printString += "Partition: " + i + "\n";
            partition = partitions.get(i);
            partitionSize = partition.size();
            for (int j = 0; j < partitionSize; j++) {
                printString += "\t[" + j + "] => ";
                entries = partition.get(j).getEntries();
                entriesSize = entries.size();
                for (int k = 0; k < entriesSize; k++) {
                    printString += "\"" + entries.get(k) + "\" ";
                }
                printString += "\n";
            }
        }
        System.out.println(printString);
    }
}
